/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.Book;
import com.qdu.service.BookService;
import com.qdu.service.impl.BookServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Lenovo
 */
@WebServlet("/abs")
public class AddBookServlet extends HttpServlet {

    BookService bookService = new BookServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 获取请求参数
        //获取新注册的图书的信息，封装成一个图书对象
        req.setCharacterEncoding("utf-8");
        String bId = req.getParameter("bId");
        String bName = req.getParameter("bName");
        String bCover = req.getParameter("bCover");
//        String bId = null;
//        String bName = null;
//        String bCover = null;
        float brating = Float.parseFloat(req.getParameter("brating"));
        Book newBook = new Book(bId, bName, bCover,brating);

        //2. 调用业务类方法执行业务逻辑，完成请求处理
        int rows = bookService.registerNewBook(newBook);

        //3. 生成响应内容，这里直接返回了受影响的行数，用于判断是否插入成功
        resp.getWriter().println(rows);
    }

}
